package com.ysynzehao.db;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * niuzehao
 * 2018/12/7 13:46.
 */
@Configuration
public class DataSourceConfiguration {

    private DataSource masterDataSerouce;

    private DataSource slaverDataSerouce;

    @Bean(name = "masterDataSerouce")
    @ConfigurationProperties(prefix = "spring.datasource.master")
    public DataSource getMasterDataSerouce() {
        masterDataSerouce = DataSourceBuilder.create().build();
        return masterDataSerouce;
    }

    @Bean(name = "slaverDataSerouce")
    @ConfigurationProperties(prefix = "spring.datasource.slaver")
    public DataSource getSlaveDataSerouce() {
        slaverDataSerouce = DataSourceBuilder.create().build();
        return slaverDataSerouce;
    }
}

